home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v2.1 / Amiga Developer CD v2.1.iso / Contributions / Haage_&_Partner / Storm-Projects / NDKExamples1 / intuition / gadgethelp.c < prev    next >
C/C++ Source or Header  |  1999-04-16  |  6KB  |  239 lines

  1. /*
  2.  * gadgethelp.c - shows help and bounds on a prop gadget
  3.  *
  4.  * (c) Copyright 1992-1996 Amiga International, Inc. All rights reserved.
  5.  *
  6.  * This software is provided as-is and is subject to change; no warranties
  7.  * are made.  All use is at your own risk.  No liability or responsibility
  8.  * is assumed.
  9.  *
  10.  * NB: If using GadTools, the correct bounds and help-properties
  11.  * are already set in GadTools gadgets.
  12.  *
  13.  * This demo shows off the gadget help feature of V39.  With this
  14.  * feature, an application can be notified when the user stops the
  15.  * mouse over a gadget.  The intent is that the application would
  16.  * then offer help (perhaps using AmigaGuide) on that gadget.
  17.  * Gadget help can be set selectively for any user gadget.  The
  18.  * application shows the correct handling of the IDCMP_GADGETHELP
  19.  * message, including decisions about when the mouse is not in
  20.  * the window, or when it's in the window but not over any help-reporting
  21.  * gadget.
  22.  *
  23.  * Note that all GadTools gadgets correctly set their bounds and
  24.  * the gadget help property.
  25.  *
  26.  */
  27.  
  28. /*------------------------------------------------------------------------*/
  29.  
  30. #include <intuition/intuitionbase.h>
  31.  
  32. #include <clib/intuition_protos.h>
  33. #include <clib/exec_protos.h>
  34.  
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37.  
  38. /*------------------------------------------------------------------------*/
  39.  
  40. void bail_out(int code);
  41.  
  42. /*------------------------------------------------------------------------*/
  43.  
  44. struct Image im =
  45. {
  46.     0,0,0,0,0,
  47.     0,
  48. };
  49.  
  50. struct PropInfo mypinfo =
  51. {
  52.     AUTOKNOB|FREEVERT,
  53.     0, 2730,    /*  VPot represents 1 on scale 0..28 with 5 visible */
  54.     0, 9362,    /*  VBody represents 0..28 with 5 visible */
  55.     0, 0, 0, 0, 0, 0,
  56. };
  57.  
  58.  
  59. struct ExtGadget myGad =
  60. {
  61.     NULL,    /*  NextGadget */
  62.     20,12,    /*  LeftEdge, TopEdge */
  63.     80,100,    /*  Width, Height */
  64.     GFLG_EXTENDED | GADGHNONE | GADGIMAGE,        /*  Flags */
  65.     GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY,    /*  Activation */
  66.     PROPGADGET,    /*  GadgetType */
  67.     &im,    /*  GadgetRender */
  68.     NULL,    /*  SelectRender */
  69.     NULL,    /*  GadgetText */
  70.     NULL,    /*  MutualExclude */
  71.     &mypinfo,    /*  SpecialInfo */
  72.     NULL,    /*  GadgetID */
  73.     NULL,    /*  UserData */
  74.     GMORE_BOUNDS|GMORE_GADGETHELP,
  75.     10,10,    /*  LeftEdge, TopEdge */
  76.     100,120,    /*  Width, Height */
  77. };
  78.  
  79. struct NewWindow testnewwindow =
  80. {
  81.     0,0,        /*  LeftEdge, TopEdge */
  82.     320,150,            /*  Width, Height */
  83.     (UBYTE)-1, (UBYTE)-1,               /*  DetailPen, BlockPen */
  84.     IDCMP_GADGETHELP | IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | IDCMP_MOUSEMOVE |
  85.     IDCMP_GADGETUP | IDCMP_GADGETDOWN,    /*  IDCMPFlags */
  86.     WFLG_DRAGBAR | WFLG_SIZEGADGET | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  87.     WFLG_NOCAREREFRESH | WFLG_SMART_REFRESH,    /* Flags */
  88.     NULL,        /*  FirstGadget */
  89.     NULL,        /*  CheckMark */
  90.     (UBYTE *) "Gadget Help Demo",    /*  Title */
  91.     NULL,        /*  Screen */
  92.     NULL,        /*  BitMap */
  93.     100,50,        /*  MinWidth, MinHeight */
  94.     640,200,        /*  MaxWidth, MaxHeight */
  95.     WBENCHSCREEN,    /*  Type */
  96. };
  97.  
  98. /*------------------------------------------------------------------------*/
  99.  
  100. struct IntuitionBase *IntuitionBase;
  101. struct Window *mywin;
  102.  
  103. /*------------------------------------------------------------------------*/
  104.  
  105. void main(void)
  106. {
  107.     BOOL terminated;
  108.     struct IntuiMessage *imsg;
  109.  
  110.     terminated = FALSE;
  111.     mywin = NULL;
  112.  
  113.     if (!(IntuitionBase = (struct IntuitionBase *)
  114.     OpenLibrary("intuition.library",39L)))
  115.     bail_out(20);
  116.  
  117.     if (!(mywin = OpenWindowTags(&testnewwindow,
  118.     TAG_DONE)))
  119.     bail_out(20);
  120.  
  121.     myGad.TopEdge += mywin->WScreen->Font->ta_YSize;
  122.     AddGadget( mywin, (struct Gadget *)&myGad, ~0 );
  123.     RefreshGList((struct Gadget *)&myGad, mywin, NULL, 1 );
  124.  
  125.     printf("Window at %lx, gadget at %lx\n", mywin, &myGad);
  126.  
  127.     /* Turn on Gadget Help */
  128.     HelpControl( mywin, HC_GADGETHELP );
  129.  
  130.     while (!terminated)
  131.     {
  132.     Wait (1 << mywin->UserPort->mp_SigBit);
  133.     while (imsg = (struct IntuiMessage *) GetMsg(mywin->UserPort))
  134.     {
  135.         switch ( imsg->Class )
  136.         {
  137.         case IDCMP_MOUSEMOVE:
  138.         printf("MouseMove (Pot = %ld)\n", (LONG)mypinfo.VertPot);
  139.         break;
  140.  
  141.         case IDCMP_CLOSEWINDOW:
  142.         terminated = TRUE;
  143.         break;
  144.  
  145.         case IDCMP_RAWKEY:
  146.         printf("RAWKEY %lx\n", imsg->Code);
  147.         break;
  148.  
  149.         case IDCMP_GADGETUP:
  150.         printf("Gadget Up (Pot = %ld)\n", (LONG)mypinfo.VertPot);
  151.         break;
  152.  
  153.         case IDCMP_GADGETDOWN:
  154.         printf("Gadget Down (Pot = %ld)\n", (LONG)mypinfo.VertPot);
  155.         break;
  156.  
  157.         case IDCMP_GADGETHELP:
  158.         if ( imsg->IAddress == NULL )
  159.         {
  160.             printf("Gadget Help: Mouse not over window\n");
  161.         }
  162.         else if ( imsg->IAddress == (APTR) mywin )
  163.         {
  164.             printf("Gadget Help: Mouse in window, not over a gadget\n");
  165.         }
  166.         else
  167.         {
  168.             /* Detect system gadgets.  Figure out by looking at
  169.              * system-gadget-type bits in GadgetType field:
  170.              */
  171.             LONG sysgtype =
  172.             ((struct Gadget *)imsg->IAddress)->GadgetType & 0xF0;
  173.             switch ( sysgtype )
  174.             {
  175.             case GTYP_SIZING:
  176.             printf("Gadget Help for window sizing gadget\n");
  177.             break;
  178.  
  179.             case GTYP_WDRAGGING:
  180.             printf("Gadget Help for window drag-bar\n");
  181.             break;
  182.  
  183.             case GTYP_WUPFRONT:
  184.             printf("Gadget Help for window depth gadget\n");
  185.             break;
  186.  
  187.             case GTYP_WDOWNBACK:
  188.             printf("Gadget Help for window zoom gadget\n");
  189.             break;
  190.  
  191.             case GTYP_CLOSE:
  192.             printf("Gadget Help for window close gadget\n");
  193.             break;
  194.  
  195.             case 0:
  196.             /* In this example, we only have one gadget,
  197.              * so we know which one it is.  Normally, you'd
  198.              * have to figure that out here, using the
  199.              * usual techniques you already use for other
  200.              * gadget messages.
  201.              */
  202.             printf("Gadget Help for proportional gadget, code %ld\n",
  203.                 imsg->Code);
  204.             break;
  205.  
  206.             default:
  207.                 printf("Gadget Help on some other system gadget\n");
  208.                 break;
  209.             }
  210.         }
  211.         }
  212.         ReplyMsg((struct Message *)imsg );
  213.     }
  214.     }
  215.     bail_out(0);
  216. }
  217.  
  218.  
  219. /*------------------------------------------------------------------------*/
  220.  
  221. /*/ bail_out()
  222.  *
  223.  * Close any allocated or opened stuff.
  224.  *
  225.  */
  226.  
  227. void bail_out(int code)
  228. {
  229.     if (mywin)
  230.     CloseWindow(mywin);
  231.  
  232.     if (IntuitionBase)
  233.     CloseLibrary((struct Library *)IntuitionBase);
  234.  
  235.     exit(code);
  236. }
  237.  
  238. /*------------------------------------------------------------------------*/
  239.